//package com.sun.mybatisplus.start;
//
//import com.sun.mybatisplus.quartz.QuartzJob;
//import com.sun.mybatisplus.quartz.QuartzJob2;
//import org.quartz.*;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationListener;
//import org.springframework.context.event.ContextRefreshedEvent;
//import org.springframework.stereotype.Component;
//
///**
// * 程序启动完成后触发
// */
////@Component
//public class StartApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
//
//    @Autowired
//    private Scheduler scheduler;
//
//
//    @Override
//    public void onApplicationEvent(ContextRefreshedEvent event) {
//        TriggerKey triggerKey = TriggerKey.triggerKey("trigger1", "group1");
//        TriggerKey triggerKey2 = TriggerKey.triggerKey("trigger2", "group2");
//        try {
//            Trigger trigger = scheduler.getTrigger(triggerKey);
//            if (trigger == null) {
//                trigger = TriggerBuilder.newTrigger()
//                        .withIdentity(triggerKey)
//                        .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))   //每5秒执行一次
//                        .startNow()
//                        .build();
//                JobDetail jobDetail = JobBuilder.newJob(QuartzJob.class)
//                        .withIdentity("job1", "group1")
//                        .build();
//                scheduler.scheduleJob(jobDetail, trigger);
//                scheduler.start();
//            }
//
//            Trigger trigger2 = scheduler.getTrigger(triggerKey2);
//            if (trigger2 == null) {
//                trigger2 = TriggerBuilder.newTrigger()
//                        .withIdentity(triggerKey2)
//                        .withSchedule(CronScheduleBuilder.cronSchedule("0/4 * * * * ?"))   //每5秒执行一次
//                        .startNow()
//                        .build();
//                JobDetail jobDetail = JobBuilder.newJob(QuartzJob2.class)
//                        .withIdentity("job2", "group2")
//                        .build();
//                scheduler.scheduleJob(jobDetail, trigger2);
//                scheduler.start();
//            }
//
//        } catch (SchedulerException e) {
//            e.printStackTrace();
//        }
//    }
//}
